from sqlalchemy import Table, Column, Integer, String
from sqlalchemy.orm import mapper
from database import metadata, db_session, init_db, engine
from sqlalchemy import ForeignKey
from sqlalchemy.types import Date, DateTime
import datetime
from sqlalchemy.orm import relationship, backref
from proyecto import Proyecto, proyecto
from usuario import Usuario, usuario
from tipoItem import TipoItem, tipoitem
from tipoCampo import TipoCampo, tipocampo
from atributoTipo import AtributoTipo, atributotipo
from historialItem import HistorialItem, historialItem
from atributoItem import AtributoItem, atributoItem
from item import Item, item

class HistorialAtributo(object):
    """ Clase que define el modelo de la tabla historial de atributos de un item """
    def __init__(self, valor=None):
        """ Metodo init """
        self.valor = valor

    def __repr__(self):
        return self.valor

historialAtributo = Table('historialatributo', metadata,
    Column('idhistorialatributo', Integer, primary_key=True),                      
    Column('idhistorialitem', Integer, ForeignKey('historialitem.idhistorialitem')),
    Column('idatributoitem', Integer, ForeignKey('atributoitem.idatributoitem')),
    Column('valor', String(50)),
    Column('idatributotipo', Integer, ForeignKey('atributotipo.idatributotipo')),
    Column('iditem', Integer)
)

mapper(HistorialAtributo, historialAtributo, properties={
    'historialItem' : relationship(HistorialItem, backref='historialAtributos'),
    'atributoItem' : relationship(AtributoItem, backref='historialAtributos'),
    'atributoTipo' : relationship(AtributoTipo, backref='historialAtributos')
    })